<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CreditsExchangeRule extends Model
{
    public $table = 'credits_exchange_rule';

    public $primaryKey='id_credits_exchange_rule';

    public $timestamps = false;

    public $fillable = ['status'];

    public function merchantTicket()
    {
        return $this->hasOne(MerchantTicket::class,'id_merchant_ticket','id_merchant_ticket')->where('is_delete','N');
    }

    public static function getActiveRuleByMerchantId($merchant_id)
    {
        return self::where('id_merchant',$merchant_id)
            ->where('goods_count','>',0)
            ->where('status','actived')
            ->with('merchantTicket')->get();
    }
}
